GBML manual / Motion

direction

The direction `speed` moves this instance in, in degrees (0 = east, counterclockwise).

Syntax

direction: real

Description

The direction speed moves this instance in, measured in degrees the way the whole engine measures angles: 0 is east, and increasing values turn counterclockwise on screen (a consequence of the room's y-down convention, not a separate rule to memorize - see the diagram below).

A circle showing 0 degrees pointing right (+x, east), with increasing angle sweeping counter-clockwise, and the y axis pointing down the screenA circle showing 0 degrees pointing right (+x, east), with increasing angle sweeping counter-clockwise, and the y axis pointing down the screen
A circle showing 0 degrees pointing right (+x, east), with increasing angle sweeping counter-clockwise, and the y axis pointing down the screen

Comes from a sine table under the hood, so it is accurate to within about two tenths of a degree (the table has 2,048 steps around the circle), not exact - never build logic that depends on two computed angles being bit-for-bit equal.

Example

speed = 3;
direction = 90;

Sets the bolt moving straight up the screen: 90 degrees is a quarter turn counterclockwise from east, which lands on north - the same way turning angle by 90 degrees does, not south. See dir_y for the sign flip inside the engine that keeps a y-down screen turning counterclockwise instead of the other way around.

On the GBA

Comes from a sine table: accurate to about a tenth of a degree, not exact.

See also: speeddir_todir_yWhere the machine shows through